<template>
  <div class="app-container">


    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:staProImp:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:staProImp:edit']">修改</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:staProImp:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:staProImp:export']">导出</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="printBox"
          v-hasPermi="['system:staProImp:print']">打印</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" border :data="dataList" fit @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>

      <!-- <el-table-column min-width="150" label="标准名称" prop="standardName" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-link @click="handleDetailDiag(scope.row)" type="primary">{{
            scope.row.standardName
          }}</el-link>
        </template>
      </el-table-column> -->
      <el-table-column label="状态" prop="statusName" :show-overflow-tooltip="true" width="150" />

      <el-table-column label="检测部门" prop="deptName" :show-overflow-tooltip="true" width="150" />

      <!-- <el-table-column label="文件预览" prop="fileCode" :show-overflow-tooltip="true" width="150">
        <template slot-scope="scope">
          <el-link type="primary" :href="baseUrl + item" target="_blank" v-for="item in scope.row.fileUrl.split(',')">
            {{ getFileName(item) }}
          </el-link>
        </template></el-table-column> -->
      <el-table-column label="新标准实施日期" prop="executiveDate" width="140" :show-overflow-tooltip="true" />
      <el-table-column label="旧标准名称代号" width="140" prop="oldStandardCode" :show-overflow-tooltip="true" />
      <el-table-column label="新标准名称代号" prop="newStandardCode" width="140" :show-overflow-tooltip="true" />
      <el-table-column label="标准内容更新情况" width="140" prop="changeContent" :show-overflow-tooltip="true" />
      <el-table-column label="人员配备" width="140" prop="manning" :show-overflow-tooltip="true" />
      <el-table-column label="设施配置" prop="equipment" :show-overflow-tooltip="true" />
      <el-table-column label="器具耗材" prop="applianceConsumables" width="140" :show-overflow-tooltip="true" />
      <el-table-column label="环境条件" width="140" prop="environment" :show-overflow-tooltip="true" />
      <el-table-column label="人员培训" prop="personalTraining" width="140" :show-overflow-tooltip="true" />
      <el-table-column label="检测软件" width="140" prop="detectionSoftware" :show-overflow-tooltip="true" />
      <el-table-column label="作业指导书" prop="jobInstruction" :show-overflow-tooltip="true" width="140" />
      <el-table-column label="原始观测数据记录表" prop="originalRecord" width="140" :show-overflow-tooltip="true" />
      <el-table-column label="检验检测记录表" prop="detectionRecord" width="140" :show-overflow-tooltip="true" />
      <el-table-column label="检测报告" prop="detectionReport" width="150" :show-overflow-tooltip="true" />
      <!-- <el-table-column label="创建日期" prop="createTime" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="修改人" prop="updateByName" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="修改日期" prop="updateTime" width="180" :show-overflow-tooltip="true" /> -->

      <el-table-column label="操作" align="center" width="250" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" v-hasPermi="['system:standard:ly']"
            @click="handleCode(scope.row)">二维码领用</el-button>
          <el-button size="mini" type="text" v-hasPermi="['system:standard:ff']"
            @click="handleSend(scope.row)">平台领用</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-view" v-hasPermi="['system:staProImp:info']"
            @click="handleDetail(scope.row)">详情</el-button>
          <el-button  v-if="scope.row.status == 'draft'" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:standard:edit']">修改</el-button>
          <el-button v-if="scope.row.status == 'draft'" size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:standard:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 打印模板位置 -->
    <PrintBox :pageNum="queryParams.pageNum" :total="total" :printRow="printList" id="printBox">
      <template slot="title" slot-scope="scope">
        <div style="margin-bottom: 40px">
          更新/起用检测标准审批表STET/B/17-1
        </div>
      </template>
      <template slot-scope="scope">
        <!-- 表格  class  table-page  必须-->
        <table style="border-collapse: collapse; table-layout: fixed; width: 90%" border="1" cellspacing="0"
          class="table-page" :isVertical="false">
          <tr style="height: 15mm">
            <td colspan="2" style="width: 35mm">检测部门</td>
            <td colspan="5" style="width: 80mm">{{ scope.item.deptName }}</td>
            <td colspan="2" style="width: 40mm">填表人</td>
            <td colspan="2" style="width: 45mm">
            {{ scope.item.nickName }}
            </td>
          </tr>
          <tr style="height: 15mm">
            <td colspan="2">旧标准名称代号</td>
            <td colspan="9">{{ scope.item.oldStandardCode }}</td>
          </tr>
          <tr style="height: 15mm">
            <td colspan="2">新标准名称代号</td>
            <td colspan="9">{{ scope.item.newStandardCode }}</td>
          </tr>
          <tr style="height: 15mm">
            <td colspan="2">新标准发布日期</td>
            <td colspan="5" style="width: 120mm">{{ scope.item.pushDate }}</td>
            <td colspan="2">新标准实施日期</td>
            <td colspan="2">{{ scope.item.executiveDate }}</td>
          </tr>
          <tr rowspan="4" style="height: 40mm">
            <td colspan="2">标准内容更新情况</td>
            <td colspan="9">{{ scope.item.changeContent }}</td>
          </tr>
          <tr>
            <td rowspan="10" colspan="2">执行新标准准备情况</td>
            <td colspan="2" style="text-align: left; height: 15mm; padding: 1mm; width: 40mm">
              人员配备
            </td>
            <td colspan="7" style="width: 160mm">{{ scope.item.manning }}</td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: left; height: 15mm; padding: 1mm; width: 40mm">
              设备配置
            </td>
            <td colspan="7" style="width: 160mm">{{ scope.item.equipment }}</td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: left; height: 15mm; padding: 1mm; width: 40mm">
              器具耗材
            </td>
            <td colspan="7" style="width: 60mm; padding: 1mm">{{ scope.item.applianceConsumables }}</td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: left; height: 15mm; padding: 1mm; width: 40mm">
              环境条件
            </td>
            <td colspan="7" style="width: 60mm; padding: 1mm">{{ scope.item.environment }}</td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: left; height: 15mm; padding: 1mm; width: 40mm">
              人员培训
            </td>
            <td colspan="7" style="width: 60mm; padding: 1mm">{{ scope.item.personalTraining }}</td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: left; height: 15mm; padding: 1mm; width: 40mm">
              检测软件
            </td>
            <td colspan="7" style="width: 60mm; padding: 1mm">{{ scope.item.detectionSoftware }}</td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: left; height: 15mm; padding: 1mm; width: 40mm">
              作业指导书
            </td>
            <td colspan="7" style="width: 60mm; padding: 1mm">{{ scope.item.jobInstruction }}</td>
          </tr>
          <tr rowspan="2">
            <td colspan="2" style="text-align: left; height: 15mm; padding: 1mm; width: 40mm">
              原始观测数据记录表
            </td>
            <td colspan="7" style="width: 60mm; padding: 1mm">{{ scope.item.originalRecord }}</td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: left; height: 15mm; padding: 1mm; width: 40mm">
              检验检测记录表
            </td>
            <td colspan="7" style="width: 60mm; padding: 1mm">{{ scope.item.detectionRecord }}</td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: left; height: 15mm; padding: 1mm; width: 40mm">
              检验检测报告
            </td>
            <td colspan="7" style="width: 60mm; padding: 1mm">{{ scope.item.detectionReport }}</td>
          </tr>
          <tr>
            <td colspan="2">检测部门意见</td>
            <td colspan="9" style="position: relative; height: 100px; vertical-align: bottom">
              <div style="
                  display: flex;
                  justify-content: flex-end;
                  text-align: left;
                ">
                <div style="width: 50mm">部门负责人：
                  <template v-if="CheckApprove(scope, 'bmzr').ShowImg">
                    <img style="width: 80px; " :src="CheckApprove(scope, 'bmzr').ApproveImg" />
                  </template>
                </div>
                <div style="width: 40mm">日期：{{ checkHistoryNode(scope, "bmzr").endTime }}</div>
              </div>
            </td>
          </tr>
          <tr>
            <td colspan="2">审批意见</td>
            <td colspan="9" style="position: relative; height: 100px; vertical-align: bottom">
              <div style="
                  display: flex;
                  justify-content: flex-end;
                  text-align: left;
                ">
                <div style="width: 50mm">技术负责人：
                  <template v-if="CheckApprove(scope, 'jsfzr').ShowImg">
                    <img style="width: 80px; " :src="CheckApprove(scope, 'jsfzr').ApproveImg" />
                  </template>
                </div>
                <div style="width: 40mm">日期：{{ checkHistoryNode(scope, "jsfzr").endTime }}</div>
              </div>
              <!-- <img src="@/assets/images/watermark.png" style="width: 200px; position: absolute" :style="{
                top: Math.random() * 45 - 30 + 'px',
                right: Math.random() * 90 + 30 + 'px',
                transform:
                  'rotate(' + Math.abs(Math.random() * 45 - 360) + 'deg)',
              }" /> -->
            </td>
          </tr>
        </table>
        <!-- 底部信息位置 -->
        <div class="page-bottom" style="page-break-after: always">
          <div class="desc">注：本表格自2022年7月25日起生效</div>
        </div>
      </template>
    </PrintBox>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  
  </div>
</template>
<script>
import { standardChangeList, delStandardChange } from "@/api/system/standard.js";
import { standardGetAdd } from "@/api/system/standRecord.js";
import store from "@/store";
import printStyle from "@/utils/print.js";
import Detail from "./detail.vue";

export default {
  name: "standard",
  components: {
    Detail,
  },
  // dicts: [
  //   "sys_standard_level",
  //   "sys_standard_area",
  //   "sys_standard_nature",
  //   "sys_standard_content",
  //   "sys_metering_status",
  //   "sys_availability_type",
  // ],
  data() {
    return {
      id: null,
      baseUrl: this.$VUE_APP_IMG_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      dataList: [],
      // 弹出层标题
      // 日期范围
      dateRange: [],
      // 数据范围选项
      queryParams: {
        pageNum: 1,
        keyword: undefined,
        levelValue: undefined,
        domainValue: undefined,
        contentValue: undefined,
        natureValue: undefined,
        calculateValue: undefined,
        effectValue: undefined,

        pageSize: 10,
      },
      showCode: false,

      current: {},
      showSend: false,
      form: {},
      rules: {
        typeValue: [
          {
            required: true,
            message: "请选择类型",
            trigger: "change",
          },
        ],
        num: [
          {
            required: true,
            message: "输入数量",
            trigger: "blur",
          },
        ],
      },
      textUrl: "",
      infos: [], //勾选的数据
      printList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    printBox() {
      //infos  勾选的数据 如果有勾选就打印勾选。
      if (this.infos.length) {
        this.printList = this.infos;
      } else {
        //反之打印当前整个列表
        this.printList = this.dataList;
      }
      setTimeout(() => {
        this.$print({
          printable: "printBox", //打印区域id
          type: "html", //打印类型是html
          scanStyles: false,
          targetStyles: ["*"],
          style: this.workStyle(),
        });
      }, 500);
    },
    // 可以自定义样式  printStyle 是公共样式 切勿私自修改
    workStyle() {
      return `${printStyle}
        table,
        table tr th,
        table tr td {
          padding: 4px;
        }
        .desc{
        text-align: left; font-size: 12px; margin-top: 10px
      }
            .df {
                display: flex;
              }
      `;
    },
    changeUser(e) {
      this.form.user = e.nickName;
    },
   
    handleSend(e) {
      if (e.effectName == '作废') {
        this.$confirm('该标准已作废，确定要领用吗?', '平台领用', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.form = {};
          this.current = e;
          this.showSend = true;
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      } else {
        this.form = {};
        this.current = e;
        this.showSend = true;
      }

    },
    getList() {
      this.loading = true;
      standardChangeList(
        this.addDateRangeTime(this.queryParams, this.dateRange)
      ).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleDetail(row) {
      this.$router.push(
        "./staProImpAdd?isInfo=true&id=" + row.standardChangeId
      );
    },
    handleDetailDiag(e) {
      this.$refs.Detail.show(e.standardChangeId);
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.standardChangeId);
      this.infos = selection;
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push("./staProImpAdd");
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      console.log(row);
      const configId = row.standardChangeId || this.ids;
      this.$router.push("./staProImpAdd?isEdit=true&id=" + configId);
    },
    // 获取文件名称
    getFileName(name) {
      // 如果是url那么取最后的名字 如果不是直接返回
      if (name.lastIndexOf("/") > -1) {
        return name.slice(name.lastIndexOf("/") + 1);
      } else {
        return name;
      }
    },
    handleExport() {
      this.download(
        "system/standardManager/export",
        {
          ...this.queryParams,
        },
        `标准记录表_${this.parseTime(new Date().getTime(), "{y}-{m}-{d}")}.xlsx`
      );
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userIds = row.standardChangeId || this.ids;
      let name = this.checkRow(
        userIds,
        this.dataList,
        "standardChangeId",
        "DELETE",
        "standardName"
      );
      this.$modal
        .confirm('是否确认删除此标准宣贯的数据项吗？')
        .then(function () {
          return delStandardChange(userIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
  },
};
</script>
<style scoped lang="scss">
.table-page {
  width: 100%;
}
</style>
